package org.nf.trading.controller.admin.order;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nf.trading.controller.BaseController;
import org.nf.trading.dao.OrderMapper;
import org.nf.trading.entity.Order;
import org.nf.trading.service.app.order.OrderService;
import org.nf.trading.vo.ResultVO;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/order")
@Slf4j
@RequiredArgsConstructor
@CrossOrigin
public class OrderManagementController extends BaseController {
    private final OrderService orderService;
    private final OrderMapper mapper;

    /**
     * 查询所有订单
     * @return
     */
    @GetMapping
    public ResultVO listOrders(){
        return success(orderService.selectAll());
    }

    @GetMapping("/listOrdersAll")
    public ResultVO listOrdersAll(Integer pageNum, Integer pageSize, Order order){
        ResultVO vo = new ResultVO();
        vo.setData(orderService.selectOrderAll(pageNum, pageSize, order));
        return vo;
    }
    /**
     * 通过id删除订单
     * @param orderId
     * @return
     */
    @DeleteMapping("/{orderId}")
    public ResultVO deleteOrder(@PathVariable("orderId") Integer orderId){
        return success(orderService.deleteOrder(orderId));
    }

    @PostMapping("/delOrder/{orderId}")
    public ResultVO delOrder(@PathVariable("orderId") Integer orderId){
        mapper.deleteByPrimaryKey(orderId);
        return success();
    }
}
